import {onMounted} from "vue";

const bd = uni.requireNativePlugin("amwhyh-BdspeechByCd");
const baiDuKey = {
    appid: "31101339",
    key: "bQzVxn3lvQxotG0bbR2mvo2G",
    secret: "p14P6mxIaVGGLmcAjqVVYjkPddql2nZa",
}
/** 开启语音唤醒 */
export const startWeakUp = () => {
    return new Promise((resolve, reject) => {
        console.log('开启语音接口了')
        //初始化
        bd.init(baiDuKey, function (e: any) {
            console.log(e)
            //唤醒
        })
        bd.wakeup({}, function (e: any) {
            console.log(e)
            if (e.code == 200) {
                console.log("等待唤醒")
            }
            if (e.code == 209) {
                console.log("唤醒成功！唤醒词" + e.words);
            }
            resolve({ code: 300 });
        })
    })
}
/**语音识别开始，生成文字上传文字*/
export const startShibie = () => {
    return new Promise((resolve, reject) => {
        bd.startRecognize(baiDuKey, function (res: any) {
            //一句话的结果
            if (res.code == 201) {
                //一句话的结果
                // console.log("一句话最终结果", res.words);
                resolve({words: res.words})
                bd.stopRecognize()
            }
            //字识别结果
            if (res.code == 200) {
                // console.log("字识别结果", res.words)
            }
            // "accept-audio-volume":true 开启后有语音音量数据回调   【volume】当前音量【volumePercent】当前音量的相对值（0-100）
            if (res.code == 202) {
                // console.log(res.volumePercent);
                // console.log(res.volume);
            }
        })
    })
}
